﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RailwayDAL;
using RoutesAdministration.ViewModels;
using System.Collections.ObjectModel;


namespace RoutesAdministration.Views
{
    /// <summary>
    /// Interaction logic for StationsAdministration.xaml
    /// </summary>
    public partial class StationsAdministration : UserControl
    {
        RailwayCompanyEntities dbEntity=new RailwayCompanyEntities();
        private ViewModelMain vmMain;
        public StationsAdministration()
        {
            InitializeComponent();
            vmMain = new ViewModelMain();
        }

        private void InsertButton_Click(object sender, RoutedEventArgs args)
        {
            try
            {
                Station insertStation = new Station()
                {
                    StationName = InsertStationName.Text,
                    OffsetX = int.Parse(InsertOffsetX.Text),
                    OffsetY = int.Parse(InsertOffsetY.Text)
                };
                RailwayDBManager.CreateStation(insertStation);
                vmMain.Stations.Add(insertStation);
                StationsList.ItemsSource = dbEntity.Stations.ToList();
            }
            catch (Exception e)
            {
                MessageBox.Show("Incorect Input");
            }

        }

        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            Station station = RailwayDBManager.GetStationByID(int.Parse((sender as Button).DataContext.ToString()));
            RailwayDBManager.DeleteStation(int.Parse((sender as Button).DataContext.ToString()));
            vmMain.Stations.Remove(station);
            StationsList.ItemsSource = dbEntity.Stations.ToList();
        }
    }
}
